<template>
  <!-- 出厂报告-直流电 -->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item class="item-class" label="产品名称:" prop="productName">
        <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item class="item-class" label="规格型号:" prop="unitOfMeasure">
        <el-input v-model="queryParams.unitOfMeasure" placeholder="请输入规格型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item class="item-class" label="产品条码:" prop="snCode">
        <el-input v-model="queryParams.snCode" placeholder="请输入产品条码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item class="item-class" label="检验日期:" prop="inspectTime">
        <el-date-picker clearable v-model="queryParams.inspectTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择检验日期"></el-date-picker>
      </el-form-item>

      <el-form-item class="item-class" label="检验员:" prop="inspector">
        <el-input v-model="queryParams.inspector" placeholder="请输入检验员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item class="item-class" label="审核日期:" prop="auditTime">
        <el-date-picker clearable v-model="queryParams.auditTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择审核日期"></el-date-picker>
      </el-form-item>

      <el-form-item class="item-class" label="审核员:" prop="auditor">
        <el-input v-model="queryParams.auditor" placeholder="请输入检验员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜 索</el-button>
      </el-form-item>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['produce:dc:report:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" size="mini" icon="el-icon-download" @click="handleExport" v-hasPermi="['produce:dc:report:export']">导出</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="handleDelete" v-hasPermi="['produce:dc:report:remove']">删除</el-button>
        </el-col>
      </el-row>

      <!-- 添加或修改检测项对话框 -->
      <el-dialog :title="title" :visible.sync="open" v-if="open" width="800px" append-to-body @close="cancel">
        <det :onOpen="onOpen" :id="id"></det>
      </el-dialog>
    </el-form>

    <!-- table -->
    <el-table v-loading="loading" :data="communList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>

      <el-table-column label="产品类型" align="center" prop="productType">
        <template slot-scope="scope">
          {{ scope.row.productType }}
        </template>
      </el-table-column>

      <el-table-column label="产品名称" align="center" prop="productName">
      </el-table-column>
      <el-table-column label="规格型号" align="center" prop="unitOfMeasure" />
      <el-table-column label="产品条码" align="center" prop="snCode" />
      <el-table-column label="检验员" align="center" prop="inspector" />
      <el-table-column label="检验日期" align="center" prop="inspectTime" />
      <el-table-column label="审核员" align="center" prop="auditor" />
      <el-table-column label="审核日期" align="center" prop="auditTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, '1')" v-hasPermi="['produce:dc:report:edit']">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { reqDcList, deleteRow } from "@/api/mes/pro/directCurrent";
import det from "./det.vue";
export default {
  name: "DirectCurrent",
  components: { det },
  data() {
    return {
      id: null,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产工单表格数据
      checkoutList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: null,
        specification: null,
        productBarcode: null,
      },
      // 表单参数
      form: {
        productName: "",
        specification: "",
        productBarcode: "",
        inspectDate: "",
        inspector: "",
        examineDate: "",
        auditor: "",
        checkResult: "",
      },
      // 表单校验
      rules: {},
      //tableList
      communList: [],
      // 模板列表
      // templateList: [
      //   {
      //     inspectionItems: "外观及尺寸检查",
      //     technical:
      //       "目测检查充电机（含充电连接装置）的外壳应平整，无明显凹凸痕、划伤、变形等缺陷；表面涂镀层应均匀，无脱落；零部件（包括连接装置内触头）应紧固可靠，无锈蚀、毛刺、裂纹等缺陷和损伤。应与技术分解单核对logo、丝印，颜色，警示标识外观尺寸等信息是否一致。",
      //     measuredValue: "",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "标志检查",
      //     technical:
      //       "目测检查充电机铭牌位置和内容应正确、完整。目测检查充电机接线、接地及安全标志应正确、完整。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "基本构成检查",
      //     technical:
      //       "充电机的基本构成包括：动力电源输入、功率变换单元、输出开关单元、充电电缆和车辆插头、以及控制电源、充电控制单元、人机交互单元和计量单元。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "工艺符合性检查",
      //     technical:
      //       "检查机器内部排线，紧固件，螺丝是否有松动情况，是否有漏装，接线错误等不良情况，无卡扣端子点胶是否合格，内部接线是否符合工艺文件要求。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "充电控制功能检验",
      //     technical:
      //       "充电机应能根据车辆电池管理系统模拟软件提供的数据动态调整充电输出，并根据设定的参数执行相应动作，控制充电过程且自动完成充电。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "绝缘检测功能检验",
      //     technical:
      //       "模拟充电机直流输出发生接地故障或绝缘水平下降到绝缘接地保护定值，充电机应立即切断输出，并发出告警提示。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "车辆插头锁止检验",
      //     technical:
      //       "检查充电机插头在充电过程时，应锁止枪头，枪头不可拔出；充电完成后，锁止装置可正常解锁拔出枪头。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "预充电功能检验",
      //     technical:
      //       "将充电机连接试验系统，在充电参数配置阶段，K5和K6闭合前，模拟正常的车辆端电池电压（K1和K2外侧电压与通信报文电池电压误差范围≤±5%且在充电机正常输出电压范围内），闭合K5和K6，检查充电机应在检测到正常的车辆端电池电压后，将K1和K2内侧输出电压调整到当前电池电压减去1V~10V，再闭合K1和K2。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "显示功能检验",
      //     technical:
      //       "充电机的显示功能应符合以下要求：具备待机、充电、告警状态指示灯；具备手动设定功能的充电机，应显示手动输入信息；对公用型充电机，应显示电池当前SOC、充电电压、充电电流、已充电时间、已充电电量、已充电金额；显示字符应清晰、完整，无缺损现象，可以不依靠环境光源即可辨认",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "急停功能检验",
      //     technical:
      //       "模拟启动急停装置，检查充电机应能同时切断充电机的动力电源输入和直流输出。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "门禁功能检验",
      //     technical:
      //       "门禁装置被打开（开门），检查充电机应能同时切断充电机的动力电源输入和直流输出。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "输入过压保护",
      //     technical: "输入过压保护动作值不应低于115%额定输入电压。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "输入欠压保护",
      //     technical: "输入欠压保护动作值不应高于85%额定输入电压。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "输出过压保护",
      //     technical: "输出过压保护值为输出最高电压+10V，可通过软件设置。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "输入电流过冲",
      //     technical: "充电机峰值电流不应超过额定输入电流的110%。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "蓄电池反接",
      //     technical:
      //       "将动力蓄电池与充电机输出正、负极反置，启动充电机输出，充电机应闭锁直流输出并发出告警提示。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "接触器粘连",
      //     technical:
      //       "将充电机连接试验系统，采用如短接直流输出端或者触发接触器节点信号，模拟任何一个接触器主触点为常闭状态（无法断开）或者常开状态，启动充电，检查充电机应停止绝缘检测过程，并发出告警提示。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "动力电源输入失电试验",
      //     technical:
      //       "在充电过程中模拟交流供电停电，检查充电机应能在1s内将车辆接口电压降至60V DC以下；保持充电用连接装置处于完全连接状态，恢复对充电机的交流供电，检查充电机应不能继续本次充电且不能发送停电前的充电阶段报文。",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      //   {
      //     inspectionItems: "气密测试",
      //     technical: "-25P<=测试值<=25PA;",
      //     checkResult: "",
      //   },
      // ],
      loading1: false,
      detailType: "1",
    };
  },
  created() {
    this.getList();
  },
  watch: {
    open(newVal) {
      console.log("new", newVal);
      if (!newVal) {
        this.getList();
      }
    },
  },
  methods: {
    onOpen() {
      this.open = false;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.selectedRows = selection;
    },
    // handleDetailExport() {
    //   const param = {
    //     productId: this.form.productId,
    //   };
    //   this.download(
    //     "/mes/report/inspection/exportDetails",
    //     {
    //       ...param,
    //     },
    //     `直流电桩出厂报告明细_${new Date().getTime()}.xlsx`
    //   );
    // },
    /** 导出按钮操作 */
    handleExport() {
      if (this.ids.length != 1) return this.$message.error("须勾选一条数据！");
      this.download(
        "mes/exfactoryreport/dc/exportWord",
        {
          id: this.ids[0],
        },
        `直流电桩出厂报告明细__${new Date().getTime()}.doc`
      );
    },
    /** 查询生产工单列表 */
    getList() {
      reqDcList(this.queryParams).then((res) => {
        console.log(res, "查询的res");
        if (res.code == 200) {
          this.communList = res.rows;
          this.total = res.total;
        }
      });
    },
    // 表单重置
    reset() {
      this.form = {
        interflowId: null,
        productName: "",
        specification: "",
        inspectDate: "",
        inspector: "",
        examineDate: "",
        auditor: "",
        checkResult: "",
      };
      this.loading1 = false;
      this.resetForm("form");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.id = null;
      this.$nextTick(() => {
        this.open = true;
        this.title = "添加出厂报告";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row, detailType) {
      this.detailType = detailType;
      console.log(row, "修改的row");
      this.reset();
      // this.form = row;
      this.id = row.id;
      this.$nextTick(() => {
        this.open = true;
        if (detailType === "2") {
          this.title = "出厂报告详情";
        } else {
          this.title = "修改出厂报告";
        }
      });

      // detailsReport(row.productId).then((res) => {
      //   if (res.code == 200) {
      //     this.form = res.data;
      //     this.templateList = res.data.templateList;
      //   }
      // });
    },
    // 判断当前是否是合格
    checkChange(value) {
      let bool = this.templateList.every(({ checkResult }) => checkResult == 1);
      this.form.checkResult = bool ? 1 : 0;
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除生产工单编号为"' + this.ids + '"的数据项？')
        .then(() => {
          deleteRow(this.ids).then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          });
        })

        .catch(() => { });
    },
    // 行合并
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 3) {
        let index = this.templateList.length;
        if (rowIndex % index === 0) {
          return {
            rowspan: index,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }

      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex]; // 合并行数
        const _col = this.spanArr[rowIndex] > 0 ? 1 : 0; // 合并的列数
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
  },
};
</script>
